package cn.wolfcode;


import cn.wolfcode.crm.web.interceptor.LoginInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@MapperScan("cn.wolfcode.crm.mapper")
//配置类要继承webMvc接口才能配置拦截器
public class AppConfig implements WebMvcConfigurer{

    //配置拦截器先将定义的拦截器交给spring'容器管理
    @Bean
    public LoginInterceptor loginInterceptor(){
        return new LoginInterceptor();
    }

    //配置拦截路径
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加自己的拦截器
        registry.addInterceptor(loginInterceptor())
                //拦截路径
                .addPathPatterns("/**")
                //放行路径
                .excludePathPatterns("/css/*")
                .excludePathPatterns("/js/*")
               .excludePathPatterns("/loginUser");



    }

    public static void main(String[] args) {

        SpringApplication.run(AppConfig.class,args);
    }

}
